#ifndef ST_FUNS_H
#define ST_FUNS_H

#include <fcgi_stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include "cgi_funs.h"

#include <cda/c_prtree.h>
#include <cda/c_define.h>
#include <dbo/db_funs.h>
#include <cda/c_array.h>
#include <cda/c_stack.h>
#include <cda/c_string.h>

#define SQL_CHECK_USER_ "select st_no,info_value from st_info where info_name=0 and st_no = (select st_no from st_list where st_no=%s and st_password=%s);"
#define SQL_CHECK_INFO_ "select info_name,info_value from st_info where st_no=%s order by info_name;"
#define SQL_CHECK_SCORE_ALL_ "select grade_list.build_time,grade_list.grade_level,subject_list.type_name,subject_list.mod_name,st_score.score_value from st_score,grade_list,subject_list where st_no=%s and st_score.score_name=subject_list.subject_name  and grade_list.grade_no=(select grade_no from class_list where class_no=(select class_no from class_st where st_no=%s));"
#define SQL_CHECK_SCORE_NOPASS_ "select grade_list.build_time,grade_list.grade_level,subject_list.type_name,subject_list.mod_name,st_score.score_value from st_score,grade_list,subject_list where st_no=%s and st_score.score_name=subject_list.subject_name  and  st_score.score_value<60 and grade_list.grade_no=(select grade_no from class_list where class_no=(select class_no from class_st where st_no=%s));"

#define INFO_TABLE_HEAD_ "<table border=\"1\" width=600><tr><th>类型</th><th>值</th></tr>"
#define INFO_TABLE_LINE_ "<tr><td align=center>%s</td><td align=center>%s</td></tr>"

#define SCORE_TABLE_HEAD_ "<table border=\"1\" width=600><tr><th>年度</th><th>学年</th><th>科目</th><th>模块</th><th>成绩</th></tr>"
#define SCORE_TABLE_LINE_ "<tr><td align=center>%s</td><td align=center>%s</td><td align=center>%s</td><td align=center>%s</td><td align=center>%s</td></tr>"

#define TABLE_TAIL_ "</table>"

/*html text*/
#define SIDEBAR_LOGINED_TEXT_ "<p>欢迎登录<p><a href=\"/st/?op=logout\">退出登录</a>"

#define LOGOUT_TEXT_ "<p align=right><a href=\"/st/?op=logout\">退出登录</a>"

#define SIDEBAR_SCORE_TEXT_ "<p><a href=\"/st/?op=score&var1=all\">历年成绩</a><p><a href=\"/st/?op=score&var1=nopass\">未通过成绩</a>"

typedef enum op_type
{
	NONE=0,
	LOGIN=1,
	LOGOUT=2,
	INFO=3,
	NEWS=4,
	SCORE=5
}OP_TYPE;

typedef struct html_op
{
	OP_TYPE type;
	char var1[NAME_SIZE_];
	
}HTML_OP;

/*login*/
USER_DATA* login_Check(USER_DATA *tag_data,SESSION_LIST *tag_session);

USER_DATA* user_Check(USER_DATA *tag_data,DB_LINKER *tag_db);

BOOL_ input_Check(char *in_char);

/*convert*/
char* level_Convert(C_ARRAY *tag_string,int level);

/*Html show*/
void show_Page(char *in_html,char *str1,char *str2,char *str3);

void show_Login(char *in_html);

void show_Main(char *in_html,USER_DATA *user_info);

void show_Info(char *in_html,USER_DATA *user_info,DB_LINKER *tag_db);

void show_Score(char *in_html,USER_DATA *user_info,HTML_OP *get_op,DB_LINKER *tag_db);

void show_Error();

HTML_OP* op_Get(HTML_OP *tag_op,char *get_data);

#endif
